// 新增API日志管理功能
function initApiLogPage() { ... }

// 新增服务监控初始化函数
function initServiceList() {
    fetch('/system_services')
        .then(response => response.json())
        .then(data => {
            const serviceList = document.getElementById('serviceList');
            serviceList.innerHTML = data.map(service => 
                `<li>${service.name}: ${service.memory_usage}%</li>`
            ).join('');
        })
        .catch(error => {
            console.error('Failed to fetch service data:', error);
            document.getElementById('serviceList').innerHTML = '<li>数据加载失败</li>';
        });
}

document.addEventListener('DOMContentLoaded', function() {
    const updateRedisBtn = document.getElementById('update-redis-btn');
    if (updateRedisBtn) {
        updateRedisBtn.addEventListener('click', async function(e) {
            e.preventDefault();
            const redisHost = document.getElementById('redis_host').value;
            const redisPort = document.getElementById('redis_port').value;
            const redisDb = document.getElementById('redis_db').value;
            const statusDiv = document.getElementById('redis-status');

            try {
                const response = await fetch('/update_redis_config', {
                    method: 'POST',
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                    body: new URLSearchParams({ redis_host: redisHost, redis_port: redisPort, redis_db: redisDb })
                });
                const data = await response.json();
                
                statusDiv.textContent = data.success ? 'Redis配置更新成功！' : '更新失败：' + data.message;
                statusDiv.style.color = data.success ? 'green' : 'red';
                statusDiv.style.backgroundColor = data.success ? 'rgba(0,255,0,0.1)' : 'rgba(255,0,0,0.1)';
            } catch (error) {
                statusDiv.textContent = '网络错误，请重试。';
                statusDiv.style.color = 'red';
                statusDiv.style.backgroundColor = 'rgba(255,0,0,0.1)';
            }
        });
    }
});
